package com.cwises.service.shop;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cwises.dao.shop.ShopDao;
import com.cwises.entity.shop.ShopData;
import com.cwises.entity.shop.ShopExamine;
import com.cwises.entity.shop.ShopInfo;
import com.cwises.entity.shop.ShopShowImg;
import com.orm.AbstractBaseEntityOperation;
import com.orm.IBaseEntityOperation;


@Service("shopService")
@Transactional
public class ShopServiceImpl extends AbstractBaseEntityOperation<ShopInfo> implements ShopService {
	
    @Resource(name = "shopDao")
    private ShopDao dao;
    
	@Override
	public IBaseEntityOperation<ShopInfo> getDao() {
		return dao;
	}

	@Override
	public void insertShopInfo(ShopExamine shopExamine, ShopInfo shopInfo,List<ShopShowImg> addShowImg, ShopData shopData) {
		dao.updateByCondition("insertShopExamine", shopExamine);
		dao.addEntity(shopInfo);
		String stype=shopInfo.getStype();
		if(stype!=null||!"".equals(stype)){
			String[] stypes=stype.split(",");
			List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
			for(int i=0;i<stypes.length;i++){
				Map<String,Object> map=new HashMap<String,Object>();
				map.put("shop_examine_id",shopInfo.getId());
				map.put("type_id",stypes[i]);
				list.add(map);
			}
			dao.addListOfEntity("insertTypeList", list);
		}
		if(addShowImg!=null){
			dao.addListOfEntity("insertShowImgList",addShowImg);
		}
		dao.updateByCondition("insertShopData", shopData);
	}

	@Override
	public void updateInfo(ShopExamine shopExamine, ShopInfo shopInfo) {
		dao.updateByCondition("insertShopExamine", shopExamine);
		dao.addEntity(shopInfo);
		String stype=shopInfo.getStype();
		if(stype!=null||!"".equals(stype)){
			String[] stypes=stype.split(",");
			List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
			for(int i=0;i<stypes.length;i++){
				Map<String,Object> map=new HashMap<String,Object>();
				map.put("shop_examine_id",shopInfo.getId());
				map.put("type_id",stypes[i]);
				list.add(map);
			}
			dao.addListOfEntity("insertTypeList", list);
		}
	}

	@Override
	public void updateShowImg(ShopExamine shopExamine,List<ShopShowImg> addShowImg) {
		dao.updateByCondition("insertShopExamine", shopExamine);
		if(addShowImg!=null){
			dao.addListOfEntity("insertShowImgList",addShowImg);
		}
	}

	@Override
	public void updateAplay(ShopExamine shopExamine, ShopData shopData) {
		dao.updateByCondition("insertShopExamine", shopExamine);
		dao.updateByCondition("insertShopData", shopData);
	}
}
